/*
 * 提现记录
 * page提现记录
 */
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/bloc/my/cashOutRecordBloc.dart';
import 'package:qgchat/common/class/date/index.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/models/reflectInfoModel.dart';
import 'package:qgchat/widgets/easyRefreshWidget.dart';
import 'package:qgchat/widgets/noData.dart';

class CashOutRecord extends StatefulWidget {
  CashOutRecord({Key key}) : super(key: key);

  @override
  CashOutRecordState createState() => CashOutRecordState();
}

class CashOutRecordState extends State<CashOutRecord> {
  List inviteList = [];

  CashOutRecordBloc bloc;

  @override
  Widget build(BuildContext context) {
    bloc = BlocProvider.of<CashOutRecordBloc>(context);
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(px(88)),
        child: AppBar(
          centerTitle: true,
          title: Text(
            "提现记录",
            style: TextStyle(
              color: Colors.black,
              fontSize: px(34),
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
      ),
      body: bodyHandle(),
    );
  }

  // 生成body
  Widget bodyHandle() {
    return StreamBuilder(
      stream: bloc.cashInfoStream,
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        if (snapshot.hasData) {
          if (bloc.list.isNotEmpty) {
            return Container(
              color: col("f5f7fa"),
              child: EasyRefresh(
                header: EasyRefreshSetting.header,
                footer: EasyRefreshSetting.footer,
                onLoad: () async {
                  bloc.onLoad();
                },
                child: ListView(
                  children: [
                    Container(
                      height: px(70),
                      padding: EdgeInsets.symmetric(horizontal: px(30)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text(
                            "提现状态",
                            style: TextStyle(
                              color: col("909399"),
                              fontSize: px(26),
                            ),
                          ),
                          Text(
                            "提现金额",
                            style: TextStyle(
                              color: col("909399"),
                              fontSize: px(26),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Column(
                      children: bloc.list.map<Widget>((item) {
                        return inviteInfoHandle(item);
                      }).toList(),
                    ),
                  ],
                ),
              ),
            );
          } else {
            return NoData("暂无提现记录");
          }
        } else {
          return Container();
        }
      },
    );
  }

  // 单个详情
  Widget inviteInfoHandle(ReflectInfoModel item) {
    return Container(
      height: px(120),
      color: Colors.white,
      padding: EdgeInsets.symmetric(horizontal: px(30)),
      child: Container(
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: col("edeff2"),
              width: 1,
            ),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(bottom: px(15)),
                    child: Text(
                      "提现成功",
                      style: TextStyle(
                        height: .99,
                        color: col("303133"),
                        fontSize: px(32),
                      ),
                    ),
                  ),
                  Text(
                    "${Date.simple(int.parse(item.createtime))}",
                    style: TextStyle(
                      height: .99,
                      color: col("909399"),
                      fontSize: px(28),
                    ),
                  ),
                ],
              ),
            ),
            RichText(
              text: TextSpan(
                text: "-${item.money}",
                style: TextStyle(
                  color: col("303133"),
                  fontSize: px(34),
                  fontWeight: FontWeight.bold,
                ),
                children: <TextSpan>[
                  TextSpan(
                    text: "元",
                    style: TextStyle(
                      fontWeight: FontWeight.normal,
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
